home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / dos / lock.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  3KB  |  118 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: lock.c,v 1.3 1996/10/24 15:50:32 aros Exp $
  4.     $Log: lock.c,v $
  5.     Revision 1.3  1996/10/24 15:50:32  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.2  1996/09/21 14:14:23  digulla
  9.     Hand DOSBase to DoName()
  10.  
  11.     Revision 1.1  1996/09/11 12:54:46  digulla
  12.     A couple of new DOS functions from M. Fleischer
  13.  
  14.     Desc:
  15.     Lang: english
  16. */
  17. #include <clib/exec_protos.h>
  18. #include <utility/tagitem.h>
  19. #include <dos/dosextens.h>
  20. #include <dos/filesystem.h>
  21. #include <clib/dos_protos.h>
  22. #include "dos_intern.h"
  23.  
  24. /*****************************************************************************
  25.  
  26.     NAME */
  27.     #include <clib/dos_protos.h>
  28.  
  29.     AROS_LH2(BPTR, Lock,
  30.  
  31. /*  SYNOPSIS */
  32.     AROS_LHA(STRPTR, name,       D1),
  33.     AROS_LHA(LONG,   accessMode, D2),
  34.  
  35. /*  LOCATION */
  36.     struct DosLibrary *, DOSBase, 14, Dos)
  37.  
  38. /*  FUNCTION
  39.     Gets a lock on a file or directory. There may be more than one
  40.     shared lock on a file but only one if it is an exclusive one.
  41.     Locked files or directories may not be deleted.
  42.  
  43.     INPUTS
  44.     name       - NUL terminated name of the file or directory.
  45.     accessMode - One of SHARED_LOCK
  46.                 EXCLUSIVE_LOCK
  47.  
  48.     RESULT
  49.     Handle to the file or directory or 0 if the object couldn't be locked.
  50.     IoErr() gives additional information in that case.
  51.  
  52.     NOTES
  53.     The lock structure returned by this function is different
  54.     from that of AmigaOS (in fact it is identical to a filehandle).
  55.     Do not try to read any internal fields.
  56.  
  57.     EXAMPLE
  58.  
  59.     BUGS
  60.  
  61.     SEE ALSO
  62.  
  63.     INTERNALS
  64.  
  65.     HISTORY
  66.     29-10-95    digulla automatically created from
  67.                 dos_lib.fd and clib/dos_protos.h
  68.  
  69. *****************************************************************************/
  70.  
  71. {
  72.     AROS_LIBFUNC_INIT
  73.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  74.  
  75.     struct FileHandle *ret;
  76.  
  77.     /* Get pointer to process structure */
  78.     struct Process *me=(struct Process *)FindTask(NULL);
  79.  
  80.     /* Create filehandle */
  81.     ret=(struct FileHandle *)AllocDosObject(DOS_FILEHANDLE,NULL);
  82.     if(ret!=NULL)
  83.     {
  84.     /* Get pointer to I/O request. Use stackspace for now. */
  85.     struct IOFileSys io,*iofs=&io;
  86.  
  87.     /* Prepare I/O request. */
  88.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  89.     iofs->IOFS.io_Message.mn_ReplyPort   =&me->pr_MsgPort;
  90.     iofs->IOFS.io_Message.mn_Length      =sizeof(struct IOFileSys);
  91.     iofs->IOFS.io_Flags=0;
  92.     iofs->IOFS.io_Command=FSA_OPEN;
  93.     /* io_Args[0] is the name which is set by DoName(). */
  94.     switch(accessMode)
  95.     {
  96.         case EXCLUSIVE_LOCK:
  97.         iofs->io_Args[1]=FMF_LOCK|FMF_READ;
  98.         break;
  99.         case SHARED_LOCK:
  100.         iofs->io_Args[1]=FMF_READ;
  101.         break;
  102.         default:
  103.         iofs->io_Args[1]=accessMode;
  104.         break;
  105.     }
  106.     if(!DoName(iofs,name,DOSBase))
  107.     {
  108.         ret->fh_Device=iofs->IOFS.io_Device;
  109.         ret->fh_Unit  =iofs->IOFS.io_Unit;
  110.         return MKBADDR(ret);
  111.     }
  112.     FreeDosObject(DOS_FILEHANDLE,ret);
  113.     }else
  114.     me->pr_Result2=ERROR_NO_FREE_STORE;
  115.     return 0;
  116.     AROS_LIBFUNC_EXIT
  117. } /* Lock */
  118.